home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.plaf.metal;
-
- import com.sun.java.swing.Icon;
- import com.sun.java.swing.JComponent;
- import com.sun.java.swing.JTabbedPane;
- import com.sun.java.swing.UIManager;
- import com.sun.java.swing.plaf.ComponentUI;
- import com.sun.java.swing.plaf.basic.BasicTabbedPaneUI;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.awt.Insets;
- import java.awt.Rectangle;
-
- public class MetalTabbedPaneUI extends BasicTabbedPaneUI {
- protected static Insets tabsOnTopTabAreaInsets = new Insets(4, 2, 0, 6);
- protected static Insets tabsOnLeftTabAreaInsets = new Insets(6, 4, 0, 0);
- protected static Insets tabsOnBottomTabAreaInsets = new Insets(0, 2, 4, 6);
- protected static Insets tabsOnRightTabAreaInsets = new Insets(0, 0, 6, 4);
- protected int minTabWidth = 40;
- protected Color selectColor;
- protected Color selectHighlight;
-
- protected int calculateXNudge(JTabbedPane pane, int tabPlacement, int tabIndex, boolean isSelected) {
- return 0;
- }
-
- protected int calculateYNudge(JTabbedPane pane, int tabPlacement, int tabIndex, boolean isSelected) {
- return 0;
- }
-
- public static ComponentUI createUI(JComponent x) {
- return new MetalTabbedPaneUI();
- }
-
- protected Color getColorForGap(JTabbedPane pane, int currentRun, int x, int y) {
- int selectedIndex = pane.getSelectedIndex();
- int startIndex = super.tabRuns[currentRun + 1];
- int endIndex = ((BasicTabbedPaneUI)this).lastIndexInRun(currentRun + 1, pane.getTabCount());
-
- for(int i = startIndex; i <= endIndex; ++i) {
- Rectangle tabBounds = ((BasicTabbedPaneUI)this).getTabBounds(pane, i);
- int tabLeft = tabBounds.x;
- int tabRight = tabBounds.x + tabBounds.width - 1;
- if (tabLeft + 1 < x && tabRight - 4 > x) {
- return selectedIndex == i ? this.selectColor : pane.getBackgroundAt(i);
- }
- }
-
- return ((Component)pane).getBackground();
- }
-
- protected Insets getTabAreaInsets(JTabbedPane pane, int tabPlacement) {
- Insets insets;
- switch (tabPlacement) {
- case 1:
- default:
- insets = tabsOnTopTabAreaInsets;
- break;
- case 2:
- insets = tabsOnLeftTabAreaInsets;
- break;
- case 3:
- insets = tabsOnBottomTabAreaInsets;
- break;
- case 4:
- insets = tabsOnRightTabAreaInsets;
- }
-
- return insets;
- }
-
- protected int getTabOverlay(JTabbedPane pane, int tabPlacement) {
- if (tabPlacement != 2 && tabPlacement != 4) {
- return 0;
- } else {
- int maxTabHeight = ((BasicTabbedPaneUI)this).maxTabHeight(pane);
- return maxTabHeight / 2;
- }
- }
-
- protected void installDefaults(JComponent c) {
- JTabbedPane var10000 = (JTabbedPane)c;
- super.installDefaults(c);
- this.selectColor = UIManager.getColor("TabbedPane.selected");
- this.selectHighlight = UIManager.getColor("TabbedPane.selectHighlight");
- }
-
- protected int maxTabHeight(JTabbedPane pane, FontMetrics metrics) {
- int height = metrics.getHeight();
- boolean tallerIcons = false;
-
- for(int i = 0; i < pane.getTabCount(); ++i) {
- Icon icon = pane.getIconAt(i);
- if (icon != null && icon.getIconHeight() > height) {
- tallerIcons = true;
- break;
- }
- }
-
- return super.maxTabHeight(pane, metrics) - (tallerIcons ? BasicTabbedPaneUI.spacingHeight * 2 : 0);
- }
-
- protected void normalizeTabRuns(JTabbedPane pane, int tabPlacement, int tabCount, int start, int max) {
- if (tabPlacement == 1 || tabPlacement == 3) {
- super.normalizeTabRuns(pane, tabPlacement, tabCount, start, max);
- }
-
- }
-
- protected void padSelectedTab(JTabbedPane pane, int tabPlacement, int selectedIndex) {
- }
-
- public void paint(Graphics g, JComponent c) {
- JTabbedPane pane = (JTabbedPane)c;
- int tabPlacement = pane.getTabPlacement();
- Insets insets = c.getInsets();
- Dimension size = ((Component)c).getSize();
- if (((JComponent)pane).isOpaque()) {
- g.setColor(((Component)c).getBackground());
- switch (tabPlacement) {
- case 1:
- default:
- g.fillRect(insets.left, insets.top, size.width - insets.right - insets.left, ((BasicTabbedPaneUI)this).totalTabHeight(pane, tabPlacement, super.runCount));
- this.paintHighlightBelowTab(pane);
- break;
- case 2:
- g.fillRect(insets.left, insets.top, ((BasicTabbedPaneUI)this).totalTabWidth(pane, tabPlacement, super.runCount), size.height - insets.bottom - insets.top);
- break;
- case 3:
- int totalTabHeight = ((BasicTabbedPaneUI)this).totalTabHeight(pane, tabPlacement, super.runCount);
- g.fillRect(insets.left, size.height - insets.bottom - totalTabHeight, size.width - insets.left - insets.right, totalTabHeight);
- break;
- case 4:
- int totalTabWidth = ((BasicTabbedPaneUI)this).totalTabWidth(pane, tabPlacement, super.runCount);
- g.fillRect(size.width - insets.right - totalTabWidth, insets.top, totalTabWidth, size.height - insets.top - insets.bottom);
- }
- }
-
- super.paint(g, c);
- }
-
- protected void paintBottomTabBorder(JTabbedPane pane, int tabIndex, Graphics g, int x, int y, int w, int h, int btm, int rght, boolean isSelected) {
- int currentRun = ((BasicTabbedPaneUI)this).getRunForTab(pane, pane.getTabCount(), tabIndex);
- int lastIndex = ((BasicTabbedPaneUI)this).lastIndexInRun(currentRun, pane.getTabCount());
- int firstIndex = super.tabRuns[currentRun];
- int bottom = h - 1;
- int right = w - 1;
- if (this.shouldFillGap(pane, currentRun, tabIndex, x, y)) {
- g.translate(x, y);
- g.setColor(this.getColorForGap(pane, currentRun, x, y));
- g.fillRect(1, bottom - 4, 3, 5);
- g.fillRect(4, bottom - 1, 2, 2);
- g.translate(-x, -y);
- }
-
- g.translate(x, y);
- g.setColor(super.tabDarkShadow);
- g.drawLine(1, bottom - 5, 6, bottom);
- g.drawLine(6, bottom, right, bottom);
- if (tabIndex == lastIndex) {
- g.drawLine(right, 0, right, bottom);
- }
-
- if (tabIndex != super.tabRuns[super.runCount - 1]) {
- g.drawLine(0, 0, 0, bottom);
- } else {
- g.drawLine(0, 0, 0, bottom - 6);
- }
-
- g.setColor(isSelected ? this.selectHighlight : super.tabHighlight);
- g.drawLine(1, bottom - 6, 6, bottom - 1);
- g.drawLine(1, 0, 1, bottom - 6);
- if (tabIndex == firstIndex && tabIndex != super.tabRuns[super.runCount - 1]) {
- g.setColor(pane.getSelectedIndex() == super.tabRuns[currentRun + 1] ? this.selectHighlight : super.tabHighlight);
- g.drawLine(1, bottom - 4, 1, bottom);
- }
-
- g.translate(-x, -y);
- }
-
- protected void paintContentBorderBottomEdge(Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h) {
- g.setColor(super.tabDarkShadow);
- g.drawLine(x, y + (h - 1), x + (w - 1), y + (h - 1));
- }
-
- protected void paintContentBorderLeftEdge(Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h) {
- g.setColor(super.tabDarkShadow);
- g.drawLine(x, y, x, y + (h - 1));
- }
-
- protected void paintContentBorderRightEdge(Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h) {
- g.setColor(super.tabDarkShadow);
- g.drawLine(x + (w - 1), y, x + (w - 1), y + (h - 1));
- }
-
- protected void paintContentBorderTopEdge(Graphics g, int tabPlacement, int selectedIndex, int x, int y, int width, int height) {
- g.setColor(super.tabDarkShadow);
- g.drawLine(x - 1, y, width - 2, y);
- }
-
- protected void paintFocusIndicator(Graphics g, JTabbedPane pane, int tabPlacement, Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect, boolean isSelected) {
- if (((JComponent)pane).hasFocus() && isSelected) {
- Rectangle tabRect = rects[tabIndex];
- g.setColor(super.focus);
- g.translate(tabRect.x, tabRect.y);
- int right = tabRect.width - 1;
- int bottom = tabRect.height - 1;
- switch (tabPlacement) {
- case 1:
- case 2:
- default:
- g.drawLine(2, 6, 6, 2);
- g.drawLine(2, 6, 2, bottom - 1);
- g.drawLine(6, 2, right, 2);
- g.drawLine(right, 2, right, bottom - 1);
- g.drawLine(2, bottom - 1, right, bottom - 1);
- break;
- case 3:
- g.drawLine(2, bottom - 6, 6, bottom - 2);
- g.drawLine(6, bottom - 2, right, bottom - 2);
- g.drawLine(2, 0, 2, bottom - 6);
- g.drawLine(2, 0, right, 0);
- g.drawLine(right, 0, right, bottom - 2);
- break;
- case 4:
- g.drawLine(right - 6, 2, right - 2, 6);
- g.drawLine(1, 2, right - 6, 2);
- g.drawLine(right - 2, 6, right - 2, bottom);
- g.drawLine(1, 2, 1, bottom);
- g.drawLine(1, bottom, right - 2, bottom);
- }
-
- g.translate(-tabRect.x, -tabRect.y);
- }
-
- }
-
- protected void paintHighlightBelowTab(JTabbedPane pane) {
- }
-
- protected void paintLeftTabBorder(JTabbedPane pane, int tabIndex, Graphics g, int x, int y, int w, int h, int btm, int rght, boolean isSelected) {
- int currentRun = ((BasicTabbedPaneUI)this).getRunForTab(pane, pane.getTabCount(), tabIndex);
- int lastIndex = ((BasicTabbedPaneUI)this).lastIndexInRun(currentRun, pane.getTabCount());
- int firstIndex = super.tabRuns[currentRun];
- g.translate(x, y);
- int bottom = h - 1;
- int right = w - 1;
- if (tabIndex != firstIndex) {
- g.setColor(pane.getSelectedIndex() == tabIndex - 1 ? this.selectColor : pane.getBackgroundAt(tabIndex - 1));
- g.fillRect(2, 0, 4, 3);
- g.drawLine(2, 3, 2, 3);
- }
-
- g.setColor(isSelected ? this.selectHighlight : super.tabHighlight);
- g.drawLine(1, 6, 6, 1);
- g.drawLine(6, 1, right, 1);
- g.drawLine(1, 6, 1, bottom);
- if (tabIndex != firstIndex) {
- g.setColor(pane.getSelectedIndex() == tabIndex - 1 ? this.selectHighlight : super.tabHighlight);
- g.drawLine(1, 0, 1, 4);
- }
-
- g.setColor(super.tabDarkShadow);
- g.drawLine(1, 5, 6, 0);
- g.drawLine(6, 0, right, 0);
- if (tabIndex != firstIndex) {
- g.drawLine(0, 0, 0, bottom);
- } else {
- g.drawLine(0, 6, 0, bottom);
- }
-
- if (tabIndex == lastIndex) {
- g.drawLine(0, bottom, right, bottom);
- }
-
- g.translate(-x, -y);
- }
-
- protected void paintRightTabBorder(JTabbedPane pane, int tabIndex, Graphics g, int x, int y, int w, int h, int btm, int rght, boolean isSelected) {
- int currentRun = ((BasicTabbedPaneUI)this).getRunForTab(pane, pane.getTabCount(), tabIndex);
- int lastIndex = ((BasicTabbedPaneUI)this).lastIndexInRun(currentRun, pane.getTabCount());
- int firstIndex = super.tabRuns[currentRun];
- g.translate(x, y);
- int bottom = h - 1;
- int right = w - 1;
- if (tabIndex != firstIndex) {
- g.setColor(pane.getSelectedIndex() == tabIndex - 1 ? this.selectColor : pane.getBackgroundAt(tabIndex - 1));
- g.fillRect(right - 5, 0, 5, 3);
- g.fillRect(right - 2, 3, 2, 2);
- }
-
- g.setColor(isSelected ? this.selectHighlight : super.tabHighlight);
- g.drawLine(right - 6, 1, right - 1, 6);
- g.drawLine(0, 1, right - 6, 1);
- g.drawLine(0, 1, 0, bottom);
- g.setColor(super.tabDarkShadow);
- g.drawLine(right - 6, 0, right, 6);
- g.drawLine(0, 0, right - 6, 0);
- if (tabIndex != firstIndex) {
- g.drawLine(right, 0, right, bottom);
- } else {
- g.drawLine(right, 6, right, bottom);
- }
-
- if (tabIndex == lastIndex) {
- g.drawLine(0, bottom, right, bottom);
- }
-
- g.translate(-x, -y);
- }
-
- protected void paintTabBackground(Graphics g, JTabbedPane pane, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) {
- int var10000 = h / 2;
- if (isSelected) {
- g.setColor(this.selectColor);
- } else {
- g.setColor(pane.getBackgroundAt(tabIndex));
- }
-
- switch (tabPlacement) {
- case 1:
- default:
- g.fillRect(x + 4, y + 2, w - 1 - 3, h - 1 - 1);
- g.fillRect(x + 2, y + 5, 2, h - 5);
- break;
- case 2:
- g.fillRect(x + 5, y + 1, w - 5, h - 1);
- g.fillRect(x + 2, y + 4, 3, h - 4);
- break;
- case 3:
- g.fillRect(x + 2, y, w - 2, h - 3);
- g.fillRect(x + 5, y + (h - 1) - 3, w - 5, 3);
- break;
- case 4:
- g.fillRect(x + 1, y + 1, w - 5, h - 1);
- g.fillRect(x + (w - 1) - 3, y + 5, 3, h - 1);
- }
-
- }
-
- protected void paintTabBorder(Graphics g, JTabbedPane pane, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) {
- int bottom = y + (h - 1);
- int right = x + (w - 1);
- switch (tabPlacement) {
- case 1:
- default:
- this.paintTopTabBorder(pane, tabIndex, g, x, y, w, h, bottom, right, isSelected);
- break;
- case 2:
- this.paintLeftTabBorder(pane, tabIndex, g, x, y, w, h, bottom, right, isSelected);
- break;
- case 3:
- this.paintBottomTabBorder(pane, tabIndex, g, x, y, w, h, bottom, right, isSelected);
- break;
- case 4:
- this.paintRightTabBorder(pane, tabIndex, g, x, y, w, h, bottom, right, isSelected);
- }
-
- }
-
- protected void paintTopTabBorder(JTabbedPane pane, int tabIndex, Graphics g, int x, int y, int w, int h, int btm, int rght, boolean isSelected) {
- int currentRun = ((BasicTabbedPaneUI)this).getRunForTab(pane, pane.getTabCount(), tabIndex);
- int lastIndex = ((BasicTabbedPaneUI)this).lastIndexInRun(currentRun, pane.getTabCount());
- int firstIndex = super.tabRuns[currentRun];
- if (this.shouldFillGap(pane, currentRun, tabIndex, x, y)) {
- g.translate(x, y);
- g.setColor(this.getColorForGap(pane, currentRun, x, y + 1));
- g.fillRect(1, 0, 5, 3);
- g.fillRect(1, 3, 2, 2);
- g.translate(-x, -y);
- }
-
- g.translate(x, y);
- int bottom = h - 1;
- int right = w - 1;
- g.setColor(super.tabDarkShadow);
- g.drawLine(1, 5, 6, 0);
- g.drawLine(6, 0, right, 0);
- if (tabIndex == lastIndex) {
- g.drawLine(right, 1, right, bottom);
- }
-
- if (tabIndex != super.tabRuns[super.runCount - 1]) {
- g.drawLine(0, 0, 0, bottom);
- } else {
- g.drawLine(0, 6, 0, bottom);
- }
-
- g.setColor(isSelected ? this.selectHighlight : super.tabHighlight);
- g.drawLine(1, 6, 6, 1);
- g.drawLine(6, 1, right, 1);
- g.drawLine(1, 6, 1, bottom);
- if (tabIndex == firstIndex && tabIndex != super.tabRuns[super.runCount - 1]) {
- g.setColor(pane.getSelectedIndex() == super.tabRuns[currentRun + 1] ? this.selectHighlight : super.tabHighlight);
- g.drawLine(1, 0, 1, 4);
- }
-
- g.translate(-x, -y);
- }
-
- protected void rotateTabRuns(JTabbedPane pane, int tabPlacement, int selectedRun) {
- }
-
- protected boolean shouldFillGap(JTabbedPane pane, int currentRun, int tabIndex, int x, int y) {
- boolean result = false;
- if (currentRun == super.runCount - 2) {
- Rectangle lastTabBounds = ((BasicTabbedPaneUI)this).getTabBounds(pane, pane.getTabCount() - 1);
- int lastTabRight = lastTabBounds.x + lastTabBounds.width - 1;
- if (lastTabRight > ((BasicTabbedPaneUI)this).getTabBounds(pane, tabIndex).x + 2) {
- return true;
- }
- } else {
- result = currentRun != super.runCount - 1;
- }
-
- return result;
- }
-
- protected boolean shouldPadRun(JTabbedPane pane, int tabPlacement, int run) {
- return super.runCount > 1 && run < super.runCount - 1;
- }
- }
-